/*
 * @Description: 
 * @Date: 2022-02-18 15:57:56
 * @Author: caikaixuan
 * @LastEditTime: 2022-02-18 16:06:39
 */

var db = require('../db')
var seq = require('sequelize');
const fs = require('fs')

// const HomeData = require('../models/module/HomeDataModel')
// const HomeBanner = require('../models/module/HomeBannerModel')
// const HomeFloor = require('../models/module/HomeFloorModel')
// const Goods = require('../models/module/GoodsModel')

//设置依赖关系
async function sync() {
    
    var files = fs.readdirSync(__dirname+'/module/');
    var js_files = files.filter((f) => {
        return f.endsWith('.js');
    });

    // configHomeModel()

    for (var f of js_files) {
        // console.log(`Sync Model: ${f}`);
        let model = require(__dirname +'/module/'+ f);
        // addMapping(router, mapping);
        model.sync()
    }
    // configHomeModel()

    // await db.sequelize.sync({alter:true});
    console.log('数据库同步完成----')

}


// async function configHomeModel() {
//     HomeData.hasMany(HomeBanner,{as:'banner'})
//     HomeBanner.belongsTo(HomeData)

//     HomeData.hasMany(HomeFloor,{as:'floorList'})
//     HomeFloor.belongsTo(HomeData)

//     HomeFloor.hasMany(Goods,{as:'goods'})
//     Goods.belongsTo(HomeFloor)

// }

module.exports = {
    sync:sync
}